package com.bw.service.impl;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bw.dao.RoleMapper;
import com.bw.entity.Role;
import com.bw.service.RoleService;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service(value = "roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper<Role>roleMapper;




    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ)
    @Override
    public Integer insertSelective(Role role) throws Exception {
          try {
              this.roleMapper.insertSelective(role);
              Integer a = null;
              a.toString();
              return a;
          }catch (Exception e){
              e.printStackTrace();
              throw  new RuntimeException("异常");
          }
        }

    @Override
    public Integer insertBatch(List<Role> role) throws Exception {
           return this.roleMapper.insertBatch(role) ;
        }

    @Override
    public Integer deleteByPrimaryKey(Object id) {
            return this.roleMapper.deleteByPrimaryKey(id);
    }

    public Integer deleteBatchByPrimaryKey(List<Object> ids) {
           return this.roleMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public Integer updateByPrimaryKeySelective(Role role) {
           return this.roleMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    public Role findById(Object id) {
           return (Role) this.roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> selectByCondition(Role role) {
           return (List<Role>) this.roleMapper.selectByCondition(role);
    }

    @Override
    public Integer selectCountByCondition(Role role) {
           return  this.roleMapper.selectCountByCondition(role);
    }
    @Override
    public Map<String, Set<String>> selectResourceMapByUserId(Long id) {
        Map<String, Set<String>> map = new HashMap<>();
        Set<String> roles = new HashSet<>();
        roles.add("1");
        roles.add("2");
        roles.add("3");
        roles.add("4");
        map.put("role",roles);

        Set<String> urls = new HashSet<>();
        urls.add("index.html");
        urls.add("login.html");
        map.put("urls",urls);
        return map;
    }
}
